import Vue from 'vue'
import VueRouter from 'vue-router'
import HomeView from '../views/HomeView.vue'
//import DefaultPannel from '../views/demo/PannelView.vue'

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    name: 'home',
    component: HomeView
  },
  {
    path: '/about',
    name: 'about',
    // route level code-splitting
    // this generates a separate chunk (about.[hash].js) for this route
    // which is lazy-loaded when the route is visited.
    component: () => import(/* webpackChunkName: "about" */ '../views/AboutView.vue')
  },

  {
    path: '/index',
    name: 'index',
    component: () => import('../views/IndexView.vue'),
    children: [
      {
        path: '/rbac/user',
        name: 'rbac/user',
        component: () => import('../views/rbac/UserView.vue')
      },
      {
        path: '/rbac/role',
        name: 'rbac/role',
        component: () => import('../views/rbac/RoleView.vue')
      },
      //按钮级别的权限分配
      {
        path: '/rbac/role/button',
        name: 'rbac/role/button',
        component: () => import('../views/rbac/RoleButtonView.vue')
      },
      {
        path: '/rbac/menu',
        name: 'rbac/menu',
        component: () => import('../views/rbac/MenuView.vue')
      },
      {
        path: '/employee/list',
        name: 'employee/list',
        component: () => import('../views/employee/EmployeeListView.vue')
      }
    ]
  },
  {
    path: '/rbac/user',
    name: 'rbac/user',
    component: () => import('../views/rbac/UserView.vue')
  },
  {
    path: '/rbac/role',
    name: 'rbac/role',
    component: () => import('../views/rbac/RoleView.vue')
  },
  {
    path: '/rbac/role2',
    name: 'rbac/role2',
    component: () => import('../views/rbac/RoleButtonView.vue')
  },
  {
    path: '/rbac/menu',
    name: 'rbac/menu',
    component: () => import('../views/rbac/MenuView.vue')
  },
  //demo相关
  {
    path: '/demo/login',
    name: 'demo/login',
    component: () => import('../views/demo/LoginView.vue')
  },
  {
    path: '/demo/index',
    name: 'demo/index',
    component: () => import('../views/demo/IndexView.vue'),
    redirect:'/DefaultPannel',
    children: [
      //2023/2/14
      //【面板页】，另在主路由上，需要添加redirect跳转。才能在router-view中显示面板页
      {
        path:'/DefaultPannel',
        name:'DefaultPannel',
        component: () => import('../views/demo/PannelView.vue'),
      },
      //2023/2/14  end
      
      //【rbac模块】
      {
        path: '/demo/rbac/user',
        name: 'demo/rbac/user',
        component: () => import('../views/demo/rbac/UserView.vue')
      }, {
        path: '/demo/rbac/role',
        name: 'demo/rbac/role',
        component: () => import('../views/demo/rbac/RoleView.vue')
      }, {
        path: '/demo/rbac/menu',
        name: 'demo/rbac/menu',
        component: () => import('../views/demo/rbac/MenuView.vue')
      }

      //【hr模块】
      //员工列表
      , {
        path: '/demo/hr/employee',
        name: 'demo/hr/employee',
        component: () => import('../views/demo/hr/EmployeeView.vue')
      }
    ]
  },
  //demo相关结束 ===========

  //以前月考
  {
    path:'/exam/month',
    name:'exam/month',
    component:()=> import('../views/exam/MonthExamView.vue'),
    meta:{
      auth:false
    }    
  },
  //月考模考
  {
    path:'/mock/login',
    name:'mock/login',
    component:()=>import('../views/exam/mock/LoginView.vue')
  },
  {
    path:'/mock/index',
    name:'mock/index',
    component:()=>import('../views/exam/mock/IndexView.vue'),
    children:[
      {
        path:'/mock/user',
        name:'mock/user',
        component:()=>import('../views/exam/mock/UserView.vue')
      },{
        path:'/mock/role',
        name:'mock/role',
        component:()=>import('../views/exam/mock/LoginView.vue')
      }
    ]
  },
]

const router = new VueRouter({
  routes
})

//路由守卫
// router.beforeEach((to, from, next) => {
//   if (to.path === '/demo/login') {
//     return next()
//   }

//   //根据自己实际情况，去判断是否要跳转到登录


//   //（这里只判断缓存中的token是否存在，还可以判断过期时间等）
//   let token = localStorage.getItem('token')
//   if (!token) {
//     return next('/demo/login')
//   }
//   else {

//     //过期时间 2小时
//     let out_time = 2 * 60 * 60 * 1000
//     let expires = localStorage.getItem('expires')
//     let date = new Date().getTime()

//     if (date - expires > out_time) {
//       localStorage.removeItem('token') //过期则删除token,重新定向到登录
//       next('/demo/login')
//     }
//   }
//   next()
// })

export default router
